//
//  FIAppDelegate.m
//  OpenglPing
//
//  Created by user on 12-9-23.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "FIAppDelegate.h"

#import "GLView.h"
#import "GLViewController.h"
#import "ConstantsAndMacros.h"
#import "FIMainViewController.h"
#import "ConstDef.h"
#import "FIPlayViewController.h"

@implementation FIAppDelegate

@synthesize window = _window;
@synthesize glview = _glview;
@synthesize glviewcontroller = _glviewcontroller;
@synthesize nav = _nav;
@synthesize mainviewcontroller = _mainviewcontroller;

- (void)dealloc
{
    [_window release];
    [_glview release];
    [_nav release];
    [_mainviewcontroller release];
    [super dealloc];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
//    self.glview = [[GLView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
//    self.glviewcontroller = [[GLViewController alloc] init];
//    self.glview.delegate = self.glviewcontroller;
//    [self.window addSubview:self.glview];
//    [self.window makeKeyAndVisible];
//	_glview.animationInterval = 1.0 / kRenderingFrequency;
//	[_glview startAnimation];
    
    self.mainviewcontroller = [[FIMainViewController alloc] initWithNibName:@"FIMainViewController" bundle:nil];
    self.nav = [[UINavigationController alloc] initWithRootViewController:self.mainviewcontroller];
    self.window.rootViewController = self.nav;
    [self.window makeKeyAndVisible];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pushNav:) name:Notice_Push_Play object:nil];
    
    return YES;
}

- (void)pushNav:(id)sender
{
    FIPlayViewController *viewcontroller = [[FIPlayViewController alloc] initWithNibName:@"FIPlayViewController" bundle:nil];
    NSLog(@"url:%@", sender);
    
    NSString * url = [sender object];
    NSLog(@"url:%@", url);
    [viewcontroller setPlayUrl:url];
                      
                      
    [self.nav pushViewController:viewcontroller animated:YES];
    [viewcontroller release];
}

- (void)applicationWillResignActive:(UIApplication *)application
{
    _glview.animationInterval = 1.0 / kInactiveRenderingFrequency;
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    _glview.animationInterval = 1.0 / 60.0;
}

@end
